<!--计量单位选择框-->
<template>
  <div>
    <BasicModal v-bind="$attrs" @register="register" :title="modalTitle" width="800px"
      @ok="handleOk" destroyOnClose @visible-change="visibleChange">
      <BasicTable :columns="columns" v-bind="config" :useSearchForm="true" :formConfig="formConfig"
        :api="getReceivingPrincipleList" :searchInfo="searchInfo" :rowSelection="rowSelection"
        ></BasicTable>
    </BasicModal>
  </div>
</template>
<script lang="ts">
  import {
    defineComponent,
    ref,
    unref
  } from 'vue';
  import {
    BasicModal,
    useModalInner
  } from '/@/components/Modal';
  import {
    getReceivingPrincipleList
  } from './base.api';
  import {
    createAsyncComponent
  } from '/@/utils/factory/createAsyncComponent';
  import {
    useSelectBiz
  } from '/@/components/Form/src/jeecg/hooks/useSelectBiz';
  import {
    selectProps
  } from '/@/components/Form/src/jeecg/props/props';
  import {
    useAttrs
  } from '/@/hooks/core/useAttrs';
  import {
    render
  } from '/@/utils/common/renderUtils';

  export default defineComponent({
    name: 'CalculateSelectModal',
    components: {
      //此处需要异步加载BasicTable
      BasicModal,
      BasicTable: createAsyncComponent(() => import('/@/components/Table/src/BasicTable.vue'), {
        loading: true,
      }),
    },
    props: {
      ...selectProps,
      //选择框标题
      modalTitle: {
        type: String,
        default: '收货原则',
      },
    },

    emits: ['register', 'getSelectResult'],
    setup(props, {
      emit
    }) {
      //注册弹框
      const [register, {
        closeModal
      }] = useModalInner();
      const attrs = useAttrs();
      //表格配置
      const config = {
        canResize: false,
        bordered: true,
        size: 'small',
        rowKey: unref(props).rowKey,
        labelKey: 'name',
        isRadioSelection: true,
      };
      const getBindValue = Object.assign({}, unref(props), unref(attrs), config);
      const [{
        rowSelection,
        visibleChange,
        getSelectResult
      }] = useSelectBiz(getReceivingPrincipleList, getBindValue);
      rowSelection.columnWidth = 50;                              
      const searchInfo = ref(props.params);
      //查询form
      const formConfig = {
        labelWidth: 100,
        baseColProps: {
          xs: 8,
          sm: 8,
          md: 8,
          lg: 8,
          xl: 8,
          xxl: 8,
        },
        schemas: [{
            label: '名称',
            field: 'name',
            component: 'JInput',
            colProps: {
              span: 8
            },
          },
          // {
          //   label: "交货方式",
          //   field: 'deliveryMethod',
          //   component: 'Select',
          //   colProps: { span: 6 },
          //   componentProps: {
          //     options: [{ label: '自提', value: 1 }, { label: '供应商送货', value: 0 }]
          //   }
          // },
          // {
          //   label: "默认拒收处理方式",
          //   field: 'rejectionProcessingMethod',
          //   component: 'Select',
          //   colProps: { span: 6 },
          //   componentProps: {
          //     options: [{ label: '退扣', value: 1 }, { label: '退补', value: 0 }]
          //   }
          // },
          {
            label: "是否有效",
            field: 'effectiveStatus',
            component: 'Select',
            colProps: {
              span: 6
            },
            componentProps: {
              options: [{
                label: '是',
                value: 1
              }, {
                label: '否',
                value: 0
              }]
            }
          },
        ],
      };
      //   useModal((data: any) => {
      //     console.log(data);
      //   });
      //定义表格列
      const columns = [{
          title: '编码',
          dataIndex: 'code',
          align: 'left',
          width:80
        },
        {
          title: '名称',
          dataIndex: 'name',
        },
        {
          title: '交货方式',
          align: "center",
          sorter: true,
          dataIndex: 'deliveryMethod',
          customRender: ({
            text
          }) => {
            return text == 0 ? '供应商送货' : text == 1 ? '自提' : ''
          },
        },
        {
          title: '默认拒收处理方式',
          align: "center",
          sorter: true,
          dataIndex: 'rejectionProcessingMethod',
          customRender: ({
            text
          }) => {
            return text == 0 ? '退补' : text == 1 ? '退扣' : ''
          },
        },
        {
          title: '是否有效',
          align: "center",
          sorter: true,
          dataIndex: 'effectiveStatus',
          customRender: ({
            text
          }) => {
            return text == 0 ? '否' : text == 1 ? '是' : ''
          },
        },
        {
          title: '备注',
          align: "center",
          dataIndex: 'remark'
        },
        {
          title: '第三方编码',
          align: "center",
          dataIndex: 'thirdPartyCode',
          ifShow: false
        },
      ];

      /**
       * 确定选择
       */
      function handleOk() {
        getSelectResult((options, values) => {
          //回传选项和已选择的值
          emit('getSelectResult', options, values);
          //关闭弹窗
          closeModal();
        });
      }

      return {
        config,
        handleOk,
        searchInfo,
        register,
        visibleChange,
        getReceivingPrincipleList,
        formConfig,
        getBindValue,
        columns,
        rowSelection,
      };
    },
  });

</script>
